<?php
namespace app\ad\controller;
use framework\ext\Check;
/* *
 * 广告管理
 * */
class AdlookController extends \app\base\controller\AdminController{

    //文章列表
    public function index(){
        $act = form('get.act');
        if($act == 'del'){
            $id = form('get.id',0,intval);
            $result = model('adlook')->_delete($id);
            if($result){
                $this->jsonMsg('删除成功',1);
            }else{
                $this->jsonMsg('删除失败,请查看是否包含广告资源');
            }
        }else{
            $this->id = form('get.id',0,intval);
            $page = form('get.page',0,intval);
            $this->list = model('adlook')->pager($page,20)->_select(array('ad'=>$this->id));
            $this->pager = getPage(model('adlook')->pager);
            $this->info = model('index')->_find(array('id'=>$this->id));
            $this->display();
        }
    }

    //编辑
    public function edit(){
        if($this->isPost()){
            $msg = Check::rule(array(check::must($_POST['name']),'广告位名称必须填写'));
            if(true !== $msg){
                $this->pageMsg($msg);
            }
            $data = array();
            $data = form('post',array('fid','starttime','endtime'));
            $data['uptime'] = time();
            $data['starttime'] = strtotime(form('post.starttime'));
            $data['endtime'] = strtotime(form('post.endtime'));
            $fid = form('post.fid',0,intval);
            if($fid){
                $condition['id'] = $fid;
                $rel = model('adlook')->_update($data,$condition);
            }else{
                $rel = model('adlook')->_update($data);
            }
            if($rel){
                $this->jsonMsg('自定义页面设置成功',1,url('adlook/index',array('id'=>$data['ad'])));
            }else{
                $this->jsonMsg('自定义页面设置失败');
            }
        }else{
            $this->ad = form('get.ad',0,intval);
            $this->id = form('get.id',0,intval);
            $this->adinfo = model('index')->_find(array('id'=>$this->ad));
            $this->info = model('adlook')->_find(array('id' =>$this->id));
            $this->display();
        }
    }
}